package com.tbvtc.agriculturalcreditchainserver2025.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tbvtc.agriculturalcreditchainserver2025.dto.admin.GetAllOrdersDto;
import com.tbvtc.agriculturalcreditchainserver2025.entity.Test;
import com.tbvtc.agriculturalcreditchainserver2025.mapper.AuthMapper;
import com.tbvtc.agriculturalcreditchainserver2025.mapper.TestMapper;
import com.tbvtc.agriculturalcreditchainserver2025.pojo.Iot.Response;
import com.tbvtc.agriculturalcreditchainserver2025.service.AdminService;
import com.tbvtc.agriculturalcreditchainserver2025.service.ITestService;
import com.tbvtc.agriculturalcreditchainserver2025.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {

    @Resource
    private TestMapper testMapper;

    @Override
    public PageVo getOrders(GetAllOrdersDto ordersDto) {


        Page<Test> page = new Page<>(ordersDto.getPage(), ordersDto.getSize());

        Page<Test> testPage = testMapper.selectPage(page, new LambdaQueryWrapper<Test>()
                .like(StringUtils.hasText(ordersDto.getOrderId()), Test::getOrderId, ordersDto.getOrderId())
                .like(StringUtils.hasText(ordersDto.getPhone()), Test::getPhone, ordersDto.getPhone())
                .like(StringUtils.hasText(ordersDto.getUsername()), Test::getUsername, ordersDto.getUsername())
                .eq(StringUtils.hasText(ordersDto.getState().toString()), Test::getState, ordersDto.getState())
        );
        long total = testPage.getTotal();
        List<Test> records = testPage.getRecords();

        return   new PageVo<>(total,records) ;


    }
}
